/**
  ******************************************************************************
  * @file           : fiber.h
  * @brief          : Header for main.c file.
  *                   This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  *
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __FIBER_H
#define __FIBER_H

#include <stdint.h>
#include "core_cm4.h"

#define FIBER_UART                     USART2
#define FIBER_UART_BAUDRATE            921600
#define FIBER_UART_IRQn                USART2_IRQn
#define FIBER_UART_IRQHandler          USART2_IRQHandler
#define FIBER_UART_EnableClock()       LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART2)
#define FIBER_UART_IO_EnableClock()    LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA)

#define FIBER_OUTTIMER                 TIM6
#define FIBER_OUTTIMER_IRQn            TIM6_DAC_IRQn
#define FIBER_OUTTIMER_IRQHandler      TIM6_DAC_IRQHandler
#define FIBER_OUTTIMER_EnableClock()   LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM6)

#define FIBER_GPIO_Port                GPIOA
#define FIBER_GPIO_LL_AF               LL_GPIO_AF_7
#define FIBER_TX_LL_Pin                LL_GPIO_PIN_2
#define FIBER_RX_LL_Pin                LL_GPIO_PIN_3

#define FIBER_RECV_QUE_LENGTH          5
#define FIBER_RECV_QUE_ITEMSIZE        sizeof(Fiber_RecvBufStru)

#define FIBER_FRAME_FIXLEN             8u
#define FIBER_FRAME_BUFLEN             FIBER_FRAME_FIXLEN + 4

typedef struct
{
  uint8_t cnt;
  uint8_t buf[FIBER_FRAME_BUFLEN];
}Fiber_RecvBufStru;

extern void fiber_uart_init(void);
extern void fiber_send_str(const char *buf);
extern void fiber_send_buf(const uint8_t *buf, uint32_t len);

extern void fiber_protc_init(void);
extern void fiber_protc_process(void);
extern void fiber_protc_rcvisr(__I uint8_t rcvdt);
extern void fiber_protc_rcvtimeout(void);

#endif /* __FIBER_H */
